import axios from "axios";

/** 方法装饰器工厂；
 * 实际上是闭包
 * @param url 地址
 * @returns
 */
const Get = (url: string) => {
  return (
    target: Object,
    key: string | symbol,
    descriptor: PropertyDescriptor
  ) => {
    const fnc = descriptor.value;
    axios
      .get(url)
      .then((res) => {
        fnc(res, {
          status: 200,
          success: true,
        });
      })
      .catch((e) => {
        fnc(e, {
          status: 500,
          success: false,
        });
      });
  };
};

/** 控制器类；
 * 
 */
export class Controller {
  constructor() {}

    /** 
     * 
     * @param res 
     * @param status 
     */
  @Get("https://api.apiopen.top/api/getHaoKanVideo?page=0&size=10")
  getList(res: any, status: any) {
    console.log(status, res.data.result.list);
  }
}
